﻿#region Using Directives

using System;
using System.Web.Security;
using System.Collections.Generic;

using QuickDev.Common.Utils;
using QuickDev.Common.Serialization;

using QuickDev.Model;
using QuickDev.SQLServerDAL;
using QuickDev.Caching;

#endregion

namespace QuickDev.BLL
{
    /// <summary>
    /// BLL Layer For dbo.OPM_ReturnOrderHeader.
    /// </summary>
    public class ReturnOrderHeaderBLL
    {
        #region ReturnOrderHeaderBLL.IsExist( string wangWangId , string customerCellphone )
        /// <summary>
        /// public static bool IsExist( string wangWangId , string customerCellphone )
        /// </summary>
        /// <param name="wangWangId">wangWangId</param>
        /// <param name="customerCellphone">customerCellphone</param>
        /// <returns>bool Existed</returns>
        public static bool IsExist( string wangWangId , string customerCellphone )
        {
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( wangWangId , "QuickDev.BLL.ReturnOrderHeaderBLL.IsExist() Method -- wangWangId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( customerCellphone , "QuickDev.BLL.ReturnOrderHeaderBLL.IsExist() Method -- customerCellphone" );

            return ReturnOrderHeaderDAL.IsExist( wangWangId , customerCellphone );
        }

        #endregion

        #region ReturnOrderHeaderBLL.Insert( string wangWangId, string customerName, string customerCellphone, string customerAddress , int createdBy ) Method

        /// <summary>
        /// public static int Insert( string wangWangId, string customerName, string customerCellphone, string customerAddress , int createdBy )
        /// </summary>
        /// <param name="wangWangId">wangWangId</param>
        /// <param name="customerName">customerName</param>
        /// <param name="customerCellphone">customerCellphone</param>
        /// <param name="createBy">createBy</param>
        /// <returns>Id</returns>
        public static ReturnOrderHeader Insert( string wangWangId , string customerName , string customerCellphone , string customerAddress , int createdBy )
        {
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( customerCellphone , "QuickDev.BLL.ReturnOrderHeaderBLL.Insert() Method -- customerCellphone" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( wangWangId , "QuickDev.BLL.ReturnOrderHeaderBLL.Insert() Method -- wangWangId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( customerName , "QuickDev.BLL.ReturnOrderHeaderBLL.Insert() Method -- customerName" );

            int newId = ReturnOrderHeaderDAL.Insert( wangWangId , customerName , customerCellphone , customerAddress , createdBy );

            if ( newId > 0 )
            {
                ReturnOrderHeaderCache.RemoveAllCollectionFromCache();

                return ReturnOrderHeaderCache.GetModel( newId );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ReturnOrderHeaderBLL.Update( int id, string wangWangId, string customerName, string customerCellphone, string customerAddress , int updatedBy ) Method

        /// <summary>
        /// public static bool Update( int id, string wangWangId, string customerName, string customerCellphone, string customerAddress , int updatedBy )
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="wangWangId">wangWangId</param>
        /// <param name="customerName">customerName</param>
        /// <param name="customerCellphone">customerCellphone</param>
        /// <param name="updatedBy">updatedBy</param>
        /// <returns>bool successful</returns>
        public static ReturnOrderHeader Update( int id , string wangWangId , string customerName , string customerCellphone , string customerAddress , int updatedBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( id , "QuickDev.BLL.ReturnOrderHeaderBLL.Update() Method -- id" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( customerCellphone , "QuickDev.BLL.ReturnOrderHeaderBLL.Update() Method -- customerCellphone" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( wangWangId , "QuickDev.BLL.ReturnOrderHeaderBLL.Update() Method -- wangWangId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( customerName , "QuickDev.BLL.ReturnOrderHeaderBLL.Update() Method -- customerName" );

            if ( ReturnOrderHeaderDAL.Update( id , wangWangId , customerName , customerCellphone , customerAddress , updatedBy ) )
            {
                ReturnOrderHeaderCache.RemoveAllCollectionFromCache();
                ReturnOrderHeaderCache.RemoveModelFromCache( id );

                return ReturnOrderHeaderCache.GetModel( id );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ReturnOrderHeaderBLL.UpdateStatus( int id , int returnOrderStatusId , int updatedBy ) Method

        /// <summary>
        /// public bool UpdateStatus( int id, int deletedBy )
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="returnOrderStatusId">returnOrderStatusId </param>
        /// <param name="updatedBy">updatedBy </param>
        /// <returns>bool successful</returns>
        public static ReturnOrderHeader UpdateStatus( int id , int returnOrderStatusId , int updatedBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( id , "QuickDev.BLL.ReturnOrderHeaderBLL.Delete -- id" );
            Validation.ValidateIntegerIsGreaterThanZero( returnOrderStatusId , "QuickDev.BLL.ReturnOrderHeaderBLL.Insert() Delete -- returnOrderStatusId" );

            if ( ReturnOrderHeaderDAL.UpdateStatus( id , returnOrderStatusId , updatedBy ) )
            {
                ReturnOrderHeaderCache.RemoveAllCollectionFromCache();
                ReturnOrderHeaderCache.RemoveModelFromCache( id );

                return ReturnOrderHeaderCache.GetModel( id );
            }
            else
            {
                return null;
            }
        }
        #endregion
    }
}

